package com.caiheng.api.util;

import com.google.zxing.*;
import com.google.zxing.client.j2se.BufferedImageLuminanceSource;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.common.HybridBinarizer;
import com.google.zxing.qrcode.QRCodeReader;
import com.google.zxing.qrcode.QRCodeWriter;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.util.Base64;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;

public class QrCodeCreateUtil {

    /**
     * 生成包含字符串信息的二维码图片
     * @param outputStream 文件输出流路径
     * @param content 二维码携带信息
     * @param qrCodeSize 二维码图片大小
     * @param imageFormat 二维码的格式
     * @throws WriterException
     * @throws IOException
     */
    public static boolean createQrCode(OutputStream outputStream, String content, int qrCodeSize, String imageFormat) throws WriterException, IOException {
        //设置二维码纠错级别ＭＡＰ
        Hashtable<EncodeHintType, ErrorCorrectionLevel> hintMap = new Hashtable<>();
        hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);  // 矫错级别
        QRCodeWriter qrCodeWriter = new QRCodeWriter();
        //创建比特矩阵(位矩阵)的QR码编码的字符串
        BitMatrix byteMatrix = qrCodeWriter.encode(content, BarcodeFormat.QR_CODE, qrCodeSize, qrCodeSize, hintMap);
        // 使BufferedImage勾画QRCode  (matrixWidth 是行二维码像素点)
        int matrixWidth = byteMatrix.getWidth();
        BufferedImage image = new BufferedImage(matrixWidth - 200, matrixWidth - 200, BufferedImage.TYPE_INT_RGB);
        image.createGraphics();
        Graphics2D graphics = (Graphics2D) image.getGraphics();
        graphics.setColor(Color.WHITE);
        graphics.fillRect(0, 0, matrixWidth, matrixWidth);
        // 使用比特矩阵画并保存图像
        graphics.setColor(Color.BLACK);
        for (int i = 0; i < matrixWidth; i++){
            for (int j = 0; j < matrixWidth; j++){
                if (byteMatrix.get(i, j)){
                    graphics.fillRect(i-100, j-100, 1, 1);
                }
            }
        }

        return ImageIO.write(image, imageFormat, outputStream);
    }
    //text 表示需要写入到二维码中的信息
    public static String getQR(String text){
        QRCodeWriter wr = new QRCodeWriter();
        BitMatrix matrix = null;
        try {
            matrix = wr.encode(text, BarcodeFormat.QR_CODE, 150, 150);
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            MatrixToImageWriter.writeToStream(matrix, "png", out);
            //转base64编码输出
            byte[] str = Base64.getEncoder().encode(out.toByteArray());
            String s = WxSign.byteToHex(str);// new String(str);
            System.out.println("s: " + s);
            return s;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }


    public static void test(){
        String text = "https://www.caihengyun.com/wxmini/gate/info?id=1"; // 要生成二维码的文本内容
        int width = 300; // 二维码图片的宽度
        int height = 300; // 二维码图片的高度
        String filePath = "qrcode.png"; // 保存二维码图片的文件路径

        try {
            // 创建QRCodeWriter对象
            QRCodeWriter qrCodeWriter = new QRCodeWriter();

            // 设置二维码参数
            BitMatrix bitMatrix = qrCodeWriter.encode(text, BarcodeFormat.QR_CODE, width, height);

            // 创建BufferedImage对象，并设置背景色和前景色
            BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_BINARY);
            Graphics2D graphics = image.createGraphics();
            graphics.setBackground(Color.WHITE);
            graphics.setColor(Color.BLACK);

            // 绘制二维码图像
            for (int x = 0; x < width; x++) {
                for (int y = 0; y < height; y++) {
                    if (bitMatrix.get(x, y)) {
                        graphics.fillRect(x, y, 1, 1);
                    }
                }
            }

            // 保存二维码图片
            ImageIO.write(image, "png", new File(filePath));

            System.out.println("二维码生成成功！");

            // 将二维码中的数据转换为16进制
            String hexData = convertToHex(bitMatrix);
            System.out.println("二维码数据的16进制表示：" + hexData);
        } catch (WriterException | IOException e) {
            e.printStackTrace();
        }
    }

    private static String convertToHex(BitMatrix bitMatrix) {
        StringBuilder hexData = new StringBuilder();
        int width = bitMatrix.getWidth();
        int height = bitMatrix.getHeight();

        for (int y = 0; y < height; y++) {
            for (int x = 0; x < width; x++) {
                if (bitMatrix.get(x, y)) {
                    hexData.append("1");
                } else {
                    hexData.append("0");
                }
            }
        }

        return hexData.toString();
    }



    /**
     * 生成一个二维码图片
     * @param width
     * @param height
     * @param content
     * @param filePath   图片路径
     * @return
     * @throws WriterException
     * @throws IOException
     */
    public static void createQRCode(int width, int height, String content,String filePath) throws WriterException, IOException {
        String url = "";
        try{
// 二维码基本参数设置
            Map<EncodeHintType, Object> hints = new HashMap<>();
            hints.put(EncodeHintType.CHARACTER_SET, "utf-8");// 设置编码字符集utf-8
            hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M);// 设置纠错等级L/M/Q/H,纠错等级越高越不易识别，当前设置等级为最高等级H
            hints.put(EncodeHintType.MARGIN, 0);// 可设置范围为0-10，但仅四个变化0 1(2) 3(4 5 6) 7(8 9 10)
// 生成图片类型为QRCode
            BarcodeFormat format = BarcodeFormat.QR_CODE;
// 创建位矩阵对象
            BitMatrix bitMatrix = new MultiFormatWriter().encode(content, format, width, height, hints);
// 设置位矩阵转图片的参数
//        MatrixToImageConfig config = new MatrixToImageConfig(Color.black.getRGB(), Color.white.getRGB());
// 位矩阵对象转流对象
            ByteArrayOutputStream os = new ByteArrayOutputStream();
            MatrixToImageWriter.writeToStream(bitMatrix, "JPG", os);
            byte[] b = os.toByteArray();
            String ss = WxSign.byteToHex(b);
            System.out.println("ss: " + ss);
            OutputStream outputStream = new FileOutputStream(filePath);
            outputStream.write(b);
            outputStream.close();
        }catch (Exception e){
            e.printStackTrace();
        }
    }


    /**
     * 读二维码并输出携带的信息
     */
    public static void readQrCode(InputStream inputStream) throws IOException{
        //从输入流中获取字符串信息
        BufferedImage image = ImageIO.read(inputStream);
        //将图像转换为二进制位图源
        LuminanceSource source = new BufferedImageLuminanceSource(image);
        BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
        QRCodeReader reader = new QRCodeReader();
        Result result = null ;
        try {
            result = reader.decode(bitmap);
        } catch (ReaderException e) {
            e.printStackTrace();
        }
        System.out.println(result.getText());
    }
    /**
     * 测试代码
     * @throws WriterException
     */
    public static void main(String[] args) throws IOException, WriterException {

        String sss = "424DB2000000000000003E000000280000001D000000E3FFFFFF01000100000000000000000000000000000000000000000000000000FFFFFF0000000000FE4533F882858A08BA673AE8BA70FAE8BA660AE882DD2A08FEAAABF8009DF8000F02331055461CA88A7D0C60494741007BE49670BDA22D582E49317075F125F022A90EF08CE7110017B0D3A00438FCF0CA98AFF800DB68D0FE9C9AA082B628F8BA85EFC8BA6822E0BA4BD4D882085718FE421DB0";
        System.out.println(  "字节数：" + (sss.length() / 2));
        //6956424f5277304b47676f414141414e5355684555674141414a5941414143574151414141414155656b785041414142486b6c455156523432753257735934444d5168453666686c64394478797853526644506b6e464e3058635a6c3047714658676f54474d5a722b313838374d74556c6d612b4b36504e4a31565a34616c717379696d4f6b75766558644d656f4d6c796c32787237474f6a6a532f773467584b6e366d4d754e6736686c76632f75554d646f43506655335858334b6b74705a7977797668636171624f646136435a36696e4e2b65364177536964476b786d6e5a6f303135644f55304b6c5a5963586c473033575a6c74566876394f2f63787639644b51774b416743676b37336575634954414943424e6e46327955726a4b4f5042635646482f6e436779566b676232634d71584751644568305852474e4d464e766246364e4d446955486b645677735857594d6e414f4c344f68314e68364777524f6d62356e52574c45727550523845706e7854686b353868616f53387a6f5962334d377a4473583941574c585132642f7a6d307938504578686e424a6b376e424744326a4c3766684e655a6a2b5164364c6579574961744141414141424a52553545726b4a6767673d3d
        //ffd8ffe000104a46494600010200000100010000ffdb004300080606070605080707070909080a0c140d0c0b0b0c1912130f141d1a1f1e1d1a1c1c20242e2720222c231c1c2837292c30313434341f27393d38323c2e333432ffdb0043010909090c0b0c180d0d1832211c213232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232ffc00011080064006403012200021101031101ffc4001f0000010501010101010100000000000000000102030405060708090a0bffc400b5100002010303020403050504040000017d01020300041105122131410613516107227114328191a1082342b1c11552d1f02433627282090a161718191a25262728292a3435363738393a434445464748494a535455565758595a636465666768696a737475767778797a838485868788898a92939495969798999aa2a3a4a5a6a7a8a9aab2b3b4b5b6b7b8b9bac2c3c4c5c6c7c8c9cad2d3d4d5d6d7d8d9dae1e2e3e4e5e6e7e8e9eaf1f2f3f4f5f6f7f8f9faffc4001f0100030101010101010101010000000000000102030405060708090a0bffc400b51100020102040403040705040400010277000102031104052131061241510761711322328108144291a1b1c109233352f0156272d10a162434e125f11718191a262728292a35363738393a434445464748494a535455565758595a636465666768696a737475767778797a82838485868788898a92939495969798999aa2a3a4a5a6a7a8a9aab2b3b4b5b6b7b8b9bac2c3c4c5c6c7c8c9cad2d3d4d5d6d7d8d9dae2e3e4e5e6e7e8e9eaf2f3f4f5f6f7f8f9faffda000c03010002110311003f00f3ff00865f0cbfe1637f6a7fc4dffb3fec1e57fcbb79bbf7efff006d718d9efd6bbfff008665ff00a9bbff0029bffdb68fd997fe669ffb74ff00dad5e01401efff00f0ccbff5377fe537ff00b6d1fb32ff00ccd3ff006e9ffb5a8fd997fe669ffb74ff00dad47eccbff334ff00dba7fed6a003f665ff0099a7fedd3ff6b578057d7ff0cbe26ffc2c6fed4ff8947f67fd83caff00979f377efdff00ec2e31b3dfad1f0cbe197fc2b9fed4ff0089bff687dbfcaff976f2b66cdffedb673bfdba50079ffed35ff32b7fdbdffed1a3fe1a6bfea51ffca97ff6aa3fe4dcff00ea61feddff00b74f23c8ff00bf9bb779ded8dbdf3c701f137e26ff00c2c6fecbff008947f67fd83cdff979f377efd9fec2e31b3dfad007bffc32f89bff000b1bfb53fe251fd9ff0060f2bfe5e7cddfbf7ffb0b8c6cf7eb5e01f0cbe197fc2c6fed4ff89bff0067fd83caff00976f377efdff00edae31b3dfad7d7f5f3ffeccbff334ff00dba7fed6a003fe1997fea6effca6ff00f6da3fe1997fea6eff00ca6fff006daf00af7ffd997fe669ff00b74ffdad401e0145145007bffeccbff334ff00dba7fed6a3fe1997fea6effca6ff00f6da3fe1997fea6eff00ca6fff006da3fe1997fea6effca6ff00f6da00f40f865f0cbfe15cff006a7fc4dffb43edfe57fcbb795b366fff006db39dfedd2bcfff00665ff99a7fedd3ff006b51ff000ccbff005377fe537ffb6d7a07c32f865ff0ae7fb53fe26ffda1f6ff002bfe5dbcad9b37ff00b6d9ceff006e94007c4df89bff000ae7fb2ffe251fda1f6ff37fe5e7cad9b367fb0d9ceff6e95e01f0cbe197fc2c6fed4ff89bff0067fd83caff00976f377efdff00edae31b3dfad1f0cbe26ff00c2b9fed4ff008947f687dbfcaff979f2b66cdffec3673bfdba577ffb32ff00ccd3ff006e9ffb5a80380f865f137fe15cff006a7fc4a3fb43edfe57fcbcf95b366fff0061b39dfedd28f865f137fe15cff6a7fc4a3fb43edfe57fcbcf95b366ff00f61b39dfedd28f865f137fe15cff006a7fc4a3fb43edfe57fcbcf95b366fff0061b39dfedd2bdffe197c32ff008573fda9ff00137fed0fb7f95ff2ede56cd9bffdb6ce77fb74a003e197c4dff858dfda9ff128fecffb0795ff002f3e6efdfbff00d85c6367bf5af3ff00d997fe669ffb74ff00dad5e81f0cbe197fc2b9fed4ff0089bff687dbfcaff976f2b66cdffedb673bfdba579fff00c332ff00d4ddff0094dffedb4007fc332ffd4ddff94dff00edb5e81f0cbe197fc2b9fed4ff0089bff687dbfcaff976f2b66cdffedb673bfdba579fff00c332ff00d4ddff0094dffedb47fc332ffd4ddff94dff00edb401e01457bfff00c332ff00d4ddff0094dffedb45007a07c32f865ff0ae7fb53fe26ffda1f6ff002bfe5dbcad9b37ff00b6d9ceff006e95e01f137e197fc2b9fecbff0089bff687dbfcdff976f2b66cd9fedb673bfdba57bffc32f865ff000ae7fb53fe26ff00da1f6ff2bfe5dbcad9b37ffb6d9ceff6e947c32f865ff0ae7fb53fe26ffda1f6ff002bfe5dbcad9b37ff00b6d9ceff006e9401e7ff00f2719ff52f7f617fdbdf9fe7ff00dfbdbb7c9f7ceeed8e4ff8665ffa9bbff29bff00db68fd997fe669ff00b74ffdad5e81f0cbe197fc2b9fed4ff89bff00687dbfcaff00976f2b66cdff00edb673bfdba50079ff00fc9c67fd4bdfd85ff6f7e7f9ff00f7ef6edf27df3bbb639f40f865f0cbfe15cff6a7fc4dff00b43edfe57fcbb795b366ff00f6db39dfedd2bc03e197c4dff8573fda9ff128fed0fb7f95ff002f3e56cd9bff00d86ce77fb74aefff00e1a6bfea51ff00ca97ff006aa00fa02be7ff00f938cffa97bfb0bfedefcff3ff00efdeddbe4fbe7776c73e81f137e197fc2c6fecbff89bff0067fd83cdff00976f377efd9fedae31b3dfad79ff00fc9c67fd4bdfd85ff6f7e7f9ff00f7ef6edf27df3bbb639003f665ff0099a7fedd3ff6b51ff26e7ff530ff006eff00dba791e47fdfcddbbcef6c6def9e3d03e26fc4dff8573fd97ff128fed0fb7f9bff002f3e56cd9b3fd86ce77fb74a3e26fc4dff008573fd97ff00128fed0fb7f9bff2f3e56cd9b3fd86ce77fb74a00f3fff00938cff00a97bfb0bfedefcff003ffefdeddbe4fbe7776c73e81f137e197fc2c6fecbff0089bff67fd83cdff976f377efd9fedae31b3dfad7807c4df865ff000ae7fb2ffe26ff00da1f6ff37fe5dbcad9b367fb6d9ceff6e947c4df865ff0ae7fb2ff00e26ffda1f6ff0037fe5dbcad9b367fb6d9ceff006e9401e7f457bfff00c332ff00d4ddff0094dffedb45001fb4d7fccadff6f7ff00b468ff00869aff00a947ff002a5ffdaa8ff938cffa97bfb0bfedefcff3ff00efdeddbe4fbe7776c73c07c4df865ff0ae7fb2ff00e26ffda1f6ff0037fe5dbcad9b367fb6d9ceff006e94007c4df865ff000ae7fb2ffe26ff00da1f6ff37fe5dbcad9b367fb6d9ceff6e95eff00f0cbe197fc2b9fed4ff89bff00687dbfcaff00976f2b66cdff00edb673bfdba579ff00fc9b9ffd4c3fdbbff6e9e4791ff7f376ef3bdb1b7be783fe4dcffea61feddffb74f23c8ffbf9bb779ded8dbdf3c00701f137e197fc2b9fecbff89bff00687dbfcdff00976f2b66cd9fedb673bfdba579fd7a07c4df89bff0b1bfb2ff00e251fd9ff60f37fe5e7cddfbf67fb0b8c6cf7eb5dffeccbff334ff00dba7fed6a00f40f89bf0cbfe1637f65ffc4dff00b3fec1e6ff00cbb79bbf7ecff6d718d9efd68f89bf0cbfe1637f65ff00c4dffb3fec1e6ffcbb79bbf7ecff006d718d9efd6be40af7ff00f938cffa97bfb0bfedefcff3ff00efdeddbe4fbe7776c7201e81f137e26ffc2b9fecbff8947f687dbfcdff00979f2b66cd9fec3673bfdba51f0cbe26ff00c2c6fed4ff008947f67fd83caff979f377efdffec2e31b3dfad7807c4df865ff000ae7fb2ffe26ff00da1f6ff37fe5dbcad9b367fb6d9ceff6e947c4df89bff0b1bfb2ff00e251fd9ff60f37fe5e7cddfbf67fb0b8c6cf7eb401efff00137e197fc2c6fecbff0089bff67fd83cdff976f377efd9fedae31b3dfad7807c32f89bff000ae7fb53fe251fda1f6ff2bfe5e7cad9b37ffb0d9ceff6e95dff00fc34d7fd4a3ff952ff00ed55c07c32f89bff000ae7fb53fe251fda1f6ff2bfe5e7cad9b37ffb0d9ceff6e9401dff00fc332ffd4ddff94dff00edb4578051401f7fd79ffc4df865ff000b1bfb2ffe26ff00d9ff0060f37fe5dbcddfbf67fb6b8c6cf7eb5e01f0cbe197fc2c6fed4ff89bff0067fd83caff00976f377efdff00edae31b3dfad77ff00f0ccbff5377fe537ff00b6d001ff000ccbff005377fe537ffb6d1ff0ccbff5377fe537ff00b6d1ff000ccbff005377fe537ffb6d1fb32ffccd3ff6e9ff00b5a80380f865f0cbfe1637f6a7fc4dff00b3fec1e57fcbb79bbf7eff00f6d718d9efd68f865f0cbfe1637f6a7fc4dffb3fec1e57fcbb79bbf7efff006d718d9efd6bcfebdfff00e1997fea6eff00ca6fff006da003fe4e33fea5efec2ffb7bf3fcff00fbf7b76f93ef9dddb1c9fb4d7fccadff006f7ffb46bc02bdff00fe1997fea6effca6ff00f6da00e03e197c32ff00858dfda9ff00137fecff00b0795ff2ede6efdfbffdb5c6367bf5aeff00fe1997fea6effca6ff00f6da3f665ff99a7fedd3ff006b57a07c32f865ff000ae7fb53fe26ff00da1f6ff2bfe5dbcad9b37ffb6d9ceff6e9401e01f0cbe26ffc2b9fed4ff8947f687dbfcaff00979f2b66cdff00ec3673bfdba51f0cbe197fc2c6fed4ff0089bff67fd83caff976f377efdffedae31b3dfad77ffb32ff00ccd3ff006e9ffb5abc02800a2beffa2803e7ff00d997fe669ffb74ff00dad5e015efff00b32ffccd3ff6e9ff00b5a8ff008665ff00a9bbff0029bffdb6800fd997fe669ffb74ff00dad47eccbff334ff00dba7fed6af40f865f0cbfe15cff6a7fc4dff00b43edfe57fcbb795b366ff00f6db39dfedd2bcff00f665ff0099a7fedd3ff6b5001ff2719ff52f7f617fdbdf9fe7ff00dfbdbb7c9f7ceeed8e4ff8665ffa9bbff29bff00db68ff009373ff00a987fb77fedd3c8f23fefe6edde77b636f7cf1c07c32f865ff000b1bfb53fe26ff00d9ff0060f2bfe5dbcddfbf7ffb6b8c6cf7eb401dff00fc34d7fd4a3ff952ff00ed547fc9c67fd4bdfd85ff006f7e7f9fff007ef6edf27df3bbb639f40f865f0cbfe15cff006a7fc4dffb43edfe57fcbb795b366fff006db39dfedd28f89bf0cbfe1637f65ffc4dff00b3fec1e6ff00cbb79bbf7ecff6d718d9efd6803c03e197c32ff858dfda9ff137fecffb0795ff002ede6efdfbff00db5c6367bf5a3e26fc32ff008573fd97ff00137fed0fb7f9bff2ede56cd9b3fdb6ce77fb74af7ff89bf137fe15cff65ffc4a3fb43edfe6ff00cbcf95b366cff61b39dfedd2bc03e197c4dff8573fda9ff128fed0fb7f95ff002f3e56cd9bff00d86ce77fb74a00efff00e4dcff00ea61feddff00b74f23c8ff00bf9bb779ded8dbdf3c1ff26e7ff530ff006eff00dba791e47fdfcddbbcef6c6def9e380f89bf137fe1637f65ff00c4a3fb3fec1e6ffcbcf9bbf7ecff0061718d9efd6bdffe26fc32ff00858dfd97ff00137fecff00b079bff2ede6efdfb3fdb5c6367bf5a00f9028afbfe8a00f8028a28a002bdfff00665ff99a7fedd3ff006b5145001fb32ffccd3ff6e9ff00b5a8fd997fe669ff00b74ffdad4514007eccbff334ff00dba7fed6afa028a2803e00a28a2803dfff0069aff995bfedefff0068d780514500145145007fffd9
        //ffd8ffe000104a46494600010200000100010000ffdb004300080606070605080707070909080a0c140d0c0b0b0c1912130f141d1a1f1e1d1a1c1c20242e2720222c231c1c2837292c30313434341f27393d38323c2e333432ffdb0043010909090c0b0c180d0d1832211c213232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232ffc00011080064006403012200021101031101ffc4001f0000010501010101010100000000000000000102030405060708090a0bffc400b5100002010303020403050504040000017d01020300041105122131410613516107227114328191a1082342b1c11552d1f02433627282090a161718191a25262728292a3435363738393a434445464748494a535455565758595a636465666768696a737475767778797a838485868788898a92939495969798999aa2a3a4a5a6a7a8a9aab2b3b4b5b6b7b8b9bac2c3c4c5c6c7c8c9cad2d3d4d5d6d7d8d9dae1e2e3e4e5e6e7e8e9eaf1f2f3f4f5f6f7f8f9faffc4001f0100030101010101010101010000000000000102030405060708090a0bffc400b51100020102040403040705040400010277000102031104052131061241510761711322328108144291a1b1c109233352f0156272d10a162434e125f11718191a262728292a35363738393a434445464748494a535455565758595a636465666768696a737475767778797a82838485868788898a92939495969798999aa2a3a4a5a6a7a8a9aab2b3b4b5b6b7b8b9bac2c3c4c5c6c7c8c9cad2d3d4d5d6d7d8d9dae2e3e4e5e6e7e8e9eaf2f3f4f5f6f7f8f9faffda000c03010002110311003f00e4fc03e01f086b3f0fb51f14f8ab53d4ac60b2bd36eef6a54a85c47b495f2d9892d2638f6ad4b0f087c15d4f51b6b0b3f176b925d5d4a90c29e591b9d880a326df03248eb47842c2f353fd9abc536761693dddd49aaa6c8608cc8ed836c4e147270013f85727e0bf05f8aad7c75e1eb8b8f0d6b30c116a76cf2492584aaa8a2552492570001ce6803d2fe1af86ecfc23f1fbc43a1d8493c96b6ba50d8f3b02e771b77392001d58f6ae83c53f1d7c3169e1cbb9fc35aa417babaecfb3c13da4e11f2ea1b24aaf45dc7a8e9f8557f0f7fc9d0f8b3fec151ffe836b5e01e09f0c7fc263e2fb1d03ed9f63fb5799fbff002bccdbb6367fbb919cedc75ef401e99f11b529be2b785746d534258ef27d12ca4b8d71630615b46744620798417198a5fba5beefb8cd3f0f7c42f1ef81fe19e93736da2e94de1e696486d6ee7cb3c8e5e4620859411c87fe11d3f3ecf5ff00197857e14e8d61a0e9ba468dae4f35b9b3d57ecd2c50b3b44aa87cf555724b167e1bfdaebcd731278bb41b2d2e1f164b0e9ba8e9f7cff678bc0ed3a18b4d6191e7aae0804f96c72225ff005e79e7e600e0e2f0727873c6961a4fc41f3f48b19a269a59207595d530e108d81fabae3a1fc3ad761f64f841a0ff00c4e743f156ab73abd87fa558c1710bf972cf1fcd1abfee17e52c003f30e0f51d6baf96ebc1fe11f05dfdf6b3ade87f107578a55680de4d0c9398d8a2f96a59a56dab977c0e396e0726b9cbcf873a0e9f6f6be3ebdd774db682ed3fb66dbc3d34088b32e04df64462f8618611e42771f2f38a00a7ff000b32cbe257fc49be225c41a4e910ff00a5433e99049e634e3e55539f33e5daee7ee8e40e7b1f47f893e29d1bc5df043c437fa1de7daed63960859fca78f0e2684918700f461f9d709a6fc49d0759b86b7d2fe0b69b7d3aa1768ed6249582e40c90b6e4e3240cfb8ad7d53c49a6f8a3f677f135ee97e1eb4d0a04bd8a26b6b52bb5d8496e779da8a324301d3f847340190df0e7e1a68de15f0eea9e27f106b3633eaf651dc2ac78752db119c0db0b100171d4f7ef573c37f0d7e12f8bb5192c343f136b977751c46664c08f080804e5e003ab0fceabfc4cd0b58d6fe1e7c36fec9d2afaff00c9d28799f64b779766628319da0e3383d7d0d49f00bc35af68de3abeb8d5344d4ac606d3244592ead5e252de6c4700b0033804e3d8d00757fb38ff00c93cd43fec2b27fe8a8a8a3f671ff9279a87fd8564ff00d151514018fe1bf86bf16bc23a74961a1f89b43b4b5925333260c997200272f013d147e55b1ff08f7c73ff00a1cf43ff00bf2bff00c8f5c2784b48d7ec6fe2f847e27b08ec74fd71dafa6922915ee0054dca51d599002d6e010549c67d411d3f897e01785746f0aeafaa5bea1acb4f656535c46b24d1152c88580388c1c647a8a00e83c03e01f17e8df10751f14f8ab53d36fa7bdb236eef6a58316cc7b495f2d5400b1e38f6af08f0bf8a345f0cf86ae6ead6d2ee3f1ac7705b4fd494068a188845656566da495f347287ef0e7d3d3ff67db2f0a24c2eed353bb93c50f652ade59329f2a38bce5c329d8067023fe23f78f1e9d278d2c6e347f8c3a2f8eafe3f27c35a669e61bbbddc1bcb76f39146c1973969631c29fbdec7001c0685e16d1be2bea3a65fe9367e4dd594b14de297bd95d3edcf2905cc210b01929374f2f1b971eda1e29f877e15f00788eef5fd7f4afb57846e765ad95859dc4ad3c539456dcc5997e5fddcbfc67ef2f1e9e9fe2bb8d77c45a768d6de1bb282f7c3dae44d1ea776c42490daca10078c332fcdb1dcf2adc8191d8f9ff893e0d7c36f08e9d1dfeb9af6b9696b24a2157dc9265c8240c2424f453f95004765fb3eca9e03d46d2ec69b278a1ee0359deadccde5471663cab0da067024fe13f7873e9b1e3bf8797373e15f074b7ef692e9fe15b22dab44b23869e2448bcc58b00649589c0c95ea391db9cb7f125e6b9e17bbf8c1731c09e21d0651a7dadb44a45a3c6c55497524b96c5cbf21c0e178e0e7a3b3f8b3af695e15bad53c6769a6e9b3df597da3c3cb0c6eeb78db0b61f6bb9519687ef14fbc7d0e000f84de12b44f155d78dfc3f0c769e17d46c9edecece591dae2365740c5c1dc305a2908f9cf0474e80d2be136bd63f06b5cf07cb77a69d42fef56e2291647f2828309c31d99cfeedba03d47e1c8785e7f8a1aaf896e7e2368be1bd36e9f56b736ff0034aab16d42884aab4c1c1cc23a9f5f6ae8fe297c52f06f88fe1c6ada4e93acfda2fa7f27cb8becb326edb3231e59001c0279340162c3c21f1ab4cd3adac2cfc5da1c76b6b12430a7960ed450028c9b7c9c003ad58ff847be39ff00d0e7a1ff00df95ff00e47af24d13e1e5b2e8de6f89deeec750d5edd1bc331432232df4acbc2be036c1b9e11f314fbe79e0e353e17df5bfc2ef895a9c3e3293fb3244d3cc2c3699b0eed148a3f75bbaaf3ffd7a00f6bf84de0ad4bc07e15bad2f549ed269e5bd7b856b576650a51170772a9ce50f6f4a2b63c157be2bbed1a697c61a65a69fa80b8658e2b560ca62dab863877e77161d7b0e3d4a00f23f885e27feccf8aba4f8ef46b3feddd234cd3fc89ee2ce5dd02c8c665d8d32865561e6a1c1e7e65f515ea9a4f8e3c2be25d1ac52e355d1bcfd4ede31269b25ec5236e9146612a4e58e5b6e31cfa76af24b7f0dde687e17bbf83f73240fe21d7a51a85adcc4c4da246a55887620386c5b3f0108e579e4e3971f0e358f87ff0010fc15fdad736337dbb5587cbfb23bb6364b1e73b957fbe3a67bd007a9eafe1a9b58f165ef86bc39a249e0d4b445b81e24d3ad4c62ed76ae60ca04e374992379e62e9e98f61aaf8abc77f153476d6bc27ace9be1b36ef15de9f7b1cb25a4aca92b2bc8ac8a84ee298c8eaabce718f50b2b2f15a78f351bbbbd4ed24f0bbdb85b3b2551e6c72e23cb31d80e3224fe23f7871e9e57e296f8cfe11f0e5deb97fe2ed2a4b5b5d9bd20b78cb9dcea8300c007561de8023d43c65af7887e25e8fa0f87348d4b4fd2fc3dac0b3bdfece95cc124226541e62a285440b13e01c8c13e86b43e24783b4df12789ef06a9f14ed34c837c6eba3dd4aa56dd846064234ca012096ced1f7cfae4ec7c17d6bc39ae5beab77a5d85dc1ad3a5bc9ad5ccc7e5b9b860e4ba00e401bbcc380147cc38ec0bfd0fe1df8c7e2a6b1a26a3a05dcfaf416e9717372d3c8913a8488285db20e76ba0fba3a1fc4032f418bc37e06f875a9e8b61a8e95e3bba9eec5ca6950346cf719f2d4a88c190b6d085f383f77b63347c52f0c59f8afc1be1cba96f20d02fadb4f924b2d11a21e64f23471916d1ae50ee52aa980a4e58703a567fc3bf0b68dae78ef4df1af82acffb37c3da7f9b6b736b792b99de7313e59465c6dc4b18fbc3eeb71ebce7883e21db378abc4d1789d2eefb50d22f675f0ccb0c68ab632abbe19f05778dc909f983fdc3c72720197a8e87e30f057c2fd275dff849f5cd37ed176d6dfd8fba6b7fb3e4ca777df1d766ec6d1f7f3f5ea2f9ecfc5567268b7ff0ca0f045adce37f8867b308967b487192628c0de5447f7c7dfefd0edf813c51a2fc5ed12dbc2be2db4bbd4754b447be9e66020898ab9452a6265390b2818da075fad701f147e2f4fe31274ed126bbb7d066b745b9b5ba8220cf2ac85f7061b881c27461d0f1ea0163c6ede2ad6edfc3ba6e8de19d65a0f0d235bd9eaf670caeb7aaa23549e32ab8504441c10cdf7860f193cbf8a3c3735b786adbc41ad788649fc49757022bbd26f41fb5c0a03857937397c6d44c65470ebce319f4bb0f8f1a2699f0f2db46b3b6d563d5ed74a4b5867f22231aceb10556e5f950c01e57a76ed5e69a2e8be23f8bde31bd66bfb46d51adfed134f743ca5654d91800468467057b0e86803e9bf87163f60f0f5c45ff000997fc2579bb66fb779de6797f227eef3bdfa637633fc5d3d4ad8f0df85b46f08e9d25868767f64b5925333279af265c8009cb927a28fca8a00e0fc1fe3ef17f8c7e196a9ade9da669b3ebd05efd9edad943244ea04458b6e9073b5dcfde1d07e25e78fbc5faadbdada78334cd3752d6ac53cbf10db4c1916cee3006c42d22061b9661952e3e51cf209f3cd4efef3e1dfc3fd4bc3be17bb9f59b1b9952edfc4da648638ece42c8a61263dc036235fe307128e3d64f839aaf8abc3dacccf71e13d675083c43716c64d4a48e50b1a966ccc58a10e089776723a75e73401dff008063b19fe20ea3a96b53496de3f9ac8aea7a5c4336f0440c61191b0412516127f78dcb1e0741e597d7d6ff0018ace4baba931e3c18b5d374cb3531c13408448cccd2640601a63cc8bf7578f5e93e36789352d2b56b98f4bf0f5de8f3adc441bc4d6a5a16bc530e7c9322a024671c6f3fea871c71cfdefc26d4bc21e3cd3ada2f115dd869ed6e6597c46b6cd04566c448bb19f7e016c2af2e33e6018e7900f77834d86cbe11c5a5f881a4b4820d085bea0d190cd0aac1b642301812006e80f4ef5c9f85be24fc30f08f872d343b0f12cf25adaefd8f3da4c5cee7673922203ab1ed55ec22d63c5ff668b51d46fb4ad13c33b16e2fae19dadbc476fc6e91c92aa636488b124c83137523ac7e35f0dfc32f1468d0d9697e21f08e853a5c2cad736a2db73a8561b0ed75382581ebfc238a00e2355d57e243fc65d0eeeefc3fa6c7e284b265b3b259079524589b2cc7cd2338327f10fba38f5c76f0d78a346f8b9e1dd53c4fa647633eafaec770ab1cc8ea5bcf467036b3100171d4f7ef5d9ead6dff0009eeb90789b59f10ff00c2bad5ed22fb241677926c9de31b8f9caccd13056f31d3818f91b93c81c25e41e36d3bc556bacdec5e20f10e97a1defdaadaf66599e09a18dc3798921dcaa8ea81b702463079c5006a7c49f0b6b3e2ef8dfe21b0d0ecfed7751c504cc9e6a478410c209cb903ab0fceb1fc3de1ef1b781fe266936d6da340de2168a49ad6d279a364910a48a492ae00e03ff10e9f9f7fff00093ffc2c4ff4dfb1ff00c2bef37f79ff0009479b8fb66df93ecde6e22dd9fbd8de7fd4f4e322e6a5e28d4bc6170b0ea9e0dbbf05cee8117c5774195ac15496c091a38ca87398f1bd7fd69eb9c100f34b1d274bf117887c570f8a2e67b2f154d76eba7d8da7fab9af5de40622db5805f3362e4b01827e6ee3bcf879f10ee7e1e5eb7827c6c969a5d9e9b6eec8eb1bcd2996475902b34659482b231e0761ce7af97eade16f1569dacdf6a96f6bacde416f7125c47adc76d2ed99558b0b9128c8c1037eedc7ae727ad5cb8f0a5e788bc2f69e24b6d727d7fc4379295bad2a24371770c6a59448e4333edc220c9503e7519e9900f7ff00829e16d67c23e0dbcb0d72cfec97526a0f32a79a92650c718072848eaa7f2a2a9fc02d5b52d67c0b7d71aa6a1777d3aea7222c975334ac17ca88e01624e3249c7b9a28038cf86b71a15a7c01f10cfe25b29ef7485d547da208090ef916e170432f46da7a8e9f857b3d87fa67c3cb6ff845ff00d07ced293fb2fed1cf91988795bf3bb3b7e5cfdee9debcefc15e38f855e03d1a6d2f4bf13ddcd04b70d70cd756b333062aab81b62518c20edeb4786fc71f0abc2facebbaa59789eee49f5ab8fb45cacd6b31546dced84c44081990f527a0a00e23e2ce95f122c7c2b6b2f8c3c41a6ea1a79bd458e2b58c2b09763e18e224e36861d7b8e3d3d3efe3bed1be15eb0df15668f5d805c233ae9c36131178822f022e449927dbb9e95cdcbe18f863f16fc697f7b65e22d566d4e689669a1810c48a88123c8f321ff77b9eb5a1f0f7e19deffc2aad5bc29e2bb79ec3edda879c4413c6cfb0084a90c3728f9a3239a00f34d27e246b9acf8aac7c2d6f7d22f84af6f63d3a3b09208830b17711888b805f3e59dbbb716efbb3cd1f17be171f075d4bade9cb6906833dc476f6d6cb348f2a318b2c5b703c6e473f78f51f87b1dae83e0ef176a3a3d858eab7d35d781258e108a3661d4a80242d1e1f9b7fe0c77f5158ff00133fe263a9cfa7f8effe257e078a58e4d3f52b3f9a79aebcbfb8c06f2170d3ff0000fb8bcfa806a69bf0b8f882ddaefe262da6b7ad2398e1b9b59a48956dc0055084118c86321ce09f9873d81f14345f11daf8145a784efed2c345d3f4cb88efeda61bda5b758805442c8c72155c6720f239ee3c234af0569b7df06b5cf184b3dd8d42c2f56de28d5d7ca2a4c232c36e73fbc6e84741f8fa3e93e2bf8b9a37816c6eedfc2fa3368b65a647247732480b1b748810e409c1ced19c601f6ed401e71e12f1ae9a9611787fc6f05dea7e17b54692d2cad5155a3b82f90e5c32311879782c47cc38e063d4fe2ef8c534af1f58683af79f75e11b9d3d66bed3e045df2bef97610f95618748cf0e3eef7c90784f1f69b0f883e1f69df132eda44d6b58bd16f7104440b755412460a290581c4299cb1e49f6c1e01f00f84359f87da8f8a7c55a9ea5630595e9b777b52a542e23da4af96cc496931c7b500777f11fc629a0f87bc090e99e7c1e15d52d0ade58ec56925b2d908f2b731243796ecb90c0e4fdeef5c2783e3bed67e26ea8df0aa68f4280d96e45d446f2220620ebc897932608f6ee3a56a6afe05f0ff847c65f0deffc3d7b7d776babea10cc1eed94e50490142004523224efedd2bb7f10ff00c5caf899ab7c3bd67f71a4697147a841359fcb3b49b2318666dca57f7efc050785e7ae403a4f84d7be14bef0add4be0fd32ef4fd3c5ebac915d316632ec4cb0cbbf1b4a8ebd8f1ea553f829e16d67c23e0dbcb0d72cfec97526a0f32a79a92650c718072848eaa7f2a2803cd3e1cb683a37c16d73c4faa78674dd6a7b2d4f62add42858ab081701d958800b938c7afad49a17c4cf07eb7e21d3349ff008559a1c3f6ebb8adbcdc42db37b85dd8f246719ce322ac7c35f0dde78bbe00f88743b09208eeaeb551b1e762106d16ee724027a29ed51f86be0178ab46f15691aa5c6a1a3341657b0dc48b1cd2962a8e188198c0ce07a8a00e8fc216167a67ed2be29b3b0b482d2d63d2936430462345c8b6270a3819249fc6b90f02fc60f127877c25773dfe85aaf882d52ecb3ea93ddc8521caa288cb946039c1c647dfe9cf3dbf87bfe4e87c59ff0060a8ff00f41b5ac3d53c15a9780ff677f13697aa4f6934f2dec570ad6aecca14c96eb83b954e7287b7a50054d334db3875197c6ba4fc42823bed4251ab49e1ab4b8024b9909328b33b65cbb12c63e509cb1f979c55ff00127c5fbcfece8ffe128f84d3fd87cd1b3fb4c9f2fccc1c63cc831bb1bbdf19ae53c35aafc379adf48b1d2fc3fa941e3174861b5d424909812fc8012523cd2360970d8d878fe13d2bdce2f073f88fc1761a4fc41f2357be86569a5920768919f2e108d813a2363a0fc7ad0070fa0c5e1bf037c3ad4f45b0d474af1ddd4f762e534a81a367b8cf96a54460c85b6842f9c1fbbdb19ab1f136dbfb43e1e69775ff00090ffc221b34a964fec4f33cafb566243f66dbb933b71b31b4fdfe83a1c7f877e16d1b5cf1de9be35f0559ff0066f87b4ff36d6e6d6f25733bce627cb28cb8db89631f787dd6e3d794f17f8d74dd5759f17e97e3382ef529ec6e2eadfc3cd0a2a2d9b6e75cbed642c32b0fde0ff74fa9c8057f0d783b4df1278234f1aa7c53b4d320deeeba3dd4aa56dd83b8c84699402412d9da3ef9f5c9b1e0af16ea5e0cd1a6f056a9f0f6ef579f50b86bc5b3ba46469176a8e216898b0062273ec7d2bc8ebd33c7d7fe3cf077c41d3b51d6f5bb4b8d7a1b20d6d756b12154898c89b4a98d413cbf553d473e80127c52f186b1abff00c239e6f84afbc29fd99e67d8b7174cff00abc797fbb4dbb362f4e991d2b63c01e06bcf18c09afdb7c4e9ecfc437513fdaa089cc976b1abec1bd84c1ca90a87918e57daae6a11df6b3a368f17c449a3d6350f115b85f0c4b6c3cb5b296555cb4fb0271ba480f493ee3607f7a4f835e1bbcf08fc66d6b43bf92092ead74a3bde06250ee681c60900f461da803d5fe1c78ebfe160787ae356fecefb079376d6de579fe6e7088dbb3b57fbf8c63b515b1e1bf0b68de11d3a4b0d0ecfec96b24a6664f35e4cb900139724f451f951401e6fff000ce3e0ff00fa096b9ff7fe1ffe3547fc338f83ff00e825ae7fdff87ff8d514500749e0af84da0f80f599b54d2eef529a796ddadd96ea44650a595b236a29ce5077f5a2cbe1368363e03d47c1f15dea474fbfb81712c8d2279a1818ce14ecc63f76bd41ea7f028a00e93fe11bb3ff008437fe117f327fb0ff0067ff0067f99b8799e5f97e5e738c6ec77c633dab9bf057c26d07c07accdaa69777a94d3cb6ed6ecb752232852cad91b514e7283bfad1450053f0b7c14f0df847c4769ae585eeab25d5aefd893cb1943b9190e408c1e8c7bd749e1bf0569be17d675dd52ca7bb927d6ae3ed172b33a9546dced84c28206643d49e828a2800b2f0569b63e3cd47c6114f76750bfb716f2c6cebe5050231951b739fddaf527a9fc383ff008671f07ffd04b5cffbff000fff001aa28a00ec3c0bf0e347f87ff6ff00ec9b9be9bedde5f99f6b746c6cdd8c6d55fef9eb9ed573c6be0ad37c79a343a5ea93ddc304570b70ad6aeaac582b2e0ee5618c39ede9451401d251451401ffd9
//        createQRCode(100, 100, "https://www.caihengyun.com/wxmini/gate/info?id=1","D:\\bestme.png");

//        getQR("https://www.caihengyun.com/wxmini/gate/info?id=1");
//        test();
//        OutputStream os = new FileOutputStream("E:\\bestme.png");
//
//        os.write(b);
//
//        os.close();

//        String img_key_1 = "user/coupon/user_coupon_qr_1_1.jpg";
//        String imgurl = OssUtil.getSignUrl(img_key_1);
//        return;
//        showURL();
//        createQrCode(new FileOutputStream(new File("~\\Documents\\renbao_mall\\qrcode.jpg")),"id=1",900,"JPEG");
//        InputStream inputStream = new FileInputStream(new File("~\\Documents\\renbao_mall\\qrcode.jpg"));
//        String fileName = "user_coupon_qr_1_1.jpg";
//        if (inputStream != null) {
//            //上传头像到OSS
//            String img_key = "";
//            int upload_type = OssUtil.TYPE_COUPON_QRCODE;
//            boolean bl = OssUtil.upload(inputStream, fileName, upload_type);
//            img_key = OssUtil.getUploadPrefix(upload_type) + fileName;
//            System.out.println("img_key:" + img_key);
//
//
//            String imgurl = OssUtil.getSignUrl(img_key);
//            System.out.println("imgurl:" + imgurl);
//
//        }
//        readQrCode(new FileInputStream(new File("~\\Documents\\renbao_mall\\qrcode.jpg")));
    }

    @SuppressWarnings("unchecked")
    public static String showURL() throws IOException {
        // 第一种：获取类加载的根路径   D:\git\daotie\daotie\target\classes
//        File f = new File(QrCodeCreateUtil.class.getClass().getResource("/").getPath());
//        System.out.println(f);

        // 获取当前类的所在工程路径; 如果不加“/”  获取当前类的加载目录  D:\git\daotie\daotie\target\classes\my
        File f2 = new File(QrCodeCreateUtil.class.getClass().getResource("").getPath());
        System.out.println(f2);
        return f2.getAbsolutePath();
    }
}
